#时间时区
import datetime
# Create your models here.
from django.db import models
from django.utils import timezone
from django.contrib import admin

class Question(models.Model):
    question_text = models.CharField(max_length=200) #字符字段用CharField
    pub_date = models.DateTimeField('date published') #日期时间用 DataTimeField来表示
    def __str__(self):
        return self.question_text
    # def was_published_recently(self):
    #     return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
    @admin.display(
        boolean=True,
        ordering="pub_date",
        description="Published recently?",
    )
    def was_published_recently(self):
        now = timezone.now()
        return now - datetime.timedelta(days=1) <= self.pub_date <= now

class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)  #用于定义模型之间的一对多关系（关联另一个模型的主键）。
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)  #用于存储整数类型的数据（例如年龄、数量、评分等）。
    def __str__(self):
        return self.choice_text

